package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ecable.bean.ProfileTO;
import com.ecable.daoImpl.ProfileDAO;

import com.ecable.util.UtilConstants;

public class ViewOperatorsDispAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String path = "";

		String sname = request.getParameter("sname");
		String dname = request.getParameter("dname");
		String vname = request.getParameter("vname");
		String usertype = request.getParameter("usertype");

		System.out.println("usertype" + usertype);
		Vector<ProfileTO> opv = null;

		try {

			String path1 = request.getRealPath("/images");

			opv = new ProfileDAO().getViewProfile(path1, usertype, sname,
					dname, vname);

			if (!opv.isEmpty()) {

				request.setAttribute("status", UtilConstants._OPERATOR_INFO);
				request.setAttribute("usertype", usertype);
				request.setAttribute("opinfo", opv);

				path = UtilConstants._VIEW_ALL__OPERATORS;

			} else {
				request.setAttribute("usertype", usertype);
				request.setAttribute("status", UtilConstants._NO__OPERATOR);
				path = UtilConstants._VIEW_ALL__OPERATORS;

			}

		} catch (Exception e) {

			request.setAttribute("status", UtilConstants._INVALIED_ENTRY);
			path = UtilConstants._VIEW_ALL__OPERATORS;

		}
		RequestDispatcher rd = request.getRequestDispatcher(path);

		rd.forward(request, response);

	}

}
